package restless.utilities {
	
	import flash.utils.*;
	
	/**
	 * 
	 * @author Jordan Laine
	 * 
	 */
	
	public  class Benchmark {
		
		private var before:Number;
		private var after:Number;
		
		private var casttime:Number;
		private var bPause:Boolean = false;
		
		private var pausedTime:Number;
		private var pausedTimes:Array = [];
		private var i:int;
		private var output:String = "";
		
		public function Benchmark() {
			
		}
		
		public function start(text:String = null):void {
			output = text;
			before = getTimer();
		}
		
		public function pause():void {
			bPause = !bPause;
			if (bPause) {
				pausedTime = getTimer();
			} else {
				var num:Number = getTimer();
				pausedTime = num - pausedTime;
				pausedTimes.push(pausedTime);
			}
		}
		
		public function stopNum():Number {
			after = getTimer();
			casttime = after - before;
			before = 0;
			if (pausedTimes.length > 0) {
				for (i = pausedTimes.length - 1; i > -1; i--) {
					casttime -= pausedTimes[i];
				}
				pausedTimes.length = 0;
			}
			return casttime;
		}
		
		public function stopText():String {
			after = getTimer();
			casttime = after - before;
			before = 0;
			if (pausedTimes.length > 0) {
				for (i = pausedTimes.length - 1; i > -1; i--) {
					casttime -= pausedTimes[i];
				}
				pausedTimes.length = 0;
			}
			return output + " " + casttime;
		}
		
	}

}